package it.xiuxian.personcenter.activity

import android.app.AlertDialog
import android.content.DialogInterface
import android.graphics.Color
import android.widget.LinearLayout
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import it.xiuxian.lib.base.App
import it.xiuxian.lib.base.AppManager
import it.xiuxian.lib.base.ArouterAddress
import it.xiuxian.lib.base.BaseActivity
import it.xiuxian.lib.http.SPConfig
import it.xiuxian.lib.utils.*
import it.xiuxian.personcenter.R
import it.xiuxian.personcenter.databinding.ActivityMySetBinding
import it.xiuxian.personcenter.presenter.SettingActivityPresenter
import kotlinx.android.synthetic.main.activity_my_set.*
import com.alibaba.android.arouter.facade.annotation.Autowired as Autowired

@Route(path = ArouterAddress.SETTINGACTIVITY)
class SettingActivity:BaseActivity<SettingActivityPresenter>() {
    @JvmField
    @Autowired
    var phone:String? = null
    @JvmField
    @Autowired
    var nickname:String? = null
    @JvmField
    @Autowired
    var qianming:String? = null

   lateinit var binding:ActivityMySetBinding
    override val layoutId: Int
        get() = R.layout.activity_my_set
    override val presenter: SettingActivityPresenter
        get() = SettingActivityPresenter()

    override fun initView() {
        setTitle("设置")
        binding= getViewDataBinding<ActivityMySetBinding>()
        ARouter.getInstance().inject(this)
        (binding.include.re.layoutParams as LinearLayout.LayoutParams).setMargins(0,
            DensityUtil.getStatusPix(App.INSTANCE.applicationContext)+5,0,0)
    }

    override fun initEvent() {
        binding.llGeren.setOnClickListener {
            ARouter.getInstance().build(ArouterAddress.MYDATUMACTIVITY).withString("qianming",qianming).withString("phone",phone).withString("nickname",nickname).navigation()
        }
        binding.llXiugai.setOnClickListener {
            ARouter.getInstance().build(ArouterAddress.UPDATELOGINACTIVITY).navigation()
        }
        binding.llZhuxiao.setOnClickListener {
            ARouter.getInstance().build(ArouterAddress.ZHUXIAOACTIVITY).navigation()
        }
        binding.tvTuichu.setOnClickListener {
           var builder = AlertDialog.Builder(this)
            builder.setTitle("确定退出吗")
            builder.setPositiveButton("确定", DialogInterface.OnClickListener(){ dialogInterface: DialogInterface, i: Int ->
                SPUtil.put(SPConfig.SESSION_ID,"")
                SPUtil.put(SPConfig.NUM,"")
                SPUtil.put(SPConfig.TIME,"")
                SPUtil.clear()
                LiveDataBus.get().with(RxBusCode.REGISTER).postValue(1)
                AppManager.getSingleton().finishAllActivity("MainActivity")
                ARouter.getInstance().build(ArouterAddress.LOGINACTIVITY).navigation()
                dialogInterface.dismiss()
            })
            builder.setNegativeButton("取消", DialogInterface.OnClickListener(){ dialogInterface: DialogInterface, i: Int ->
                dialogInterface.dismiss()
            })
            val dialog = builder.create()
            dialog.show()
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).textSize = 18f
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLUE)
            dialog.getButton(AlertDialog.BUTTON_NEGATIVE).textSize = 18f
            dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.BLACK)

            //mPresenter!!.getCode(SPUtil.get(SPConfig.SESSION_ID,""))
        }
        binding.tvBanben.setText(APKVersionCodeUtils.getVerName(this))
    }

}